﻿/*
 ***********************************
 时间：2017
 代码：WangSir
 脚本作用：
 ************************************
 */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary> </summary>
public class ToggleManager : MonoBehaviour
{
    public Toggle[] toggles;
    public GameObject[] shopClass;
    public Sprite[] ClickSprites;
    public Sprite[] InitSprites;
    void Start()
    {
        foreach (var item in toggles)
        {
            item.onValueChanged.AddListener(ifSelect =>
                {
                    if (ifSelect)
                        OnToggleValueChanged(item);
                });
        }
    }

    private void  InitToggleBack()
    {
        for (int i = 0; i < toggles.Length; i++)
        {
            toggles[i].GetComponentInChildren<Image>().sprite = InitSprites[i];
        }
    }


    private void ShowSprite(int num)
    {
        FalseClass();
        InitToggleBack();
        toggles[num].GetComponentInChildren<Image>().sprite = ClickSprites[num];
        shopClass[num].SetActive(true);
    }

    private void OnToggleValueChanged(Toggle item)
    {
        switch(item.name)
        {
            case "Coins":
                ShowSprite(0);
                break;

            case "Character":
                ShowSprite(1);
                break;

            case "Prop":
                ShowSprite(2);
                break;
        }
    }

    private void FalseClass()
    {
        for (int i = 0; i < shopClass.Length; i++)
        {
            shopClass[i].SetActive(false);
        }
    }

    void Update()
    {

    }
}